$(function () {

    layui.config({
        base: '/Public/'
    }).extend({
        formSelects: 'layui-formSelects/src/formSelects-v4'
    });

    layui.use(['form','formSelects'],function () {
        var form = layui.form();
        var formSelects = layui.formSelects;

        //指派人员
        formSelects.btns('toUser', ['select', 'remove', 'reverse']);
        //渲染数据
        formSelects.data('toUser', 'server', {  //'local' | 'server', 本地数据或者远程数据
            url: "http://yapi.demo.qunar.com/mock/9813/layui/data",
            beforeSuccess: function(id, url, searchVal, result){
                //我要把数据外层的code, msg, data去掉
                result = result.data;
                //我要反转name
                /*$.each(result, function(index, item) {
                    item.name && (item.name = item.name.split('').reverse().join(''))
                });*/
                //然后返回数据
                return result;
            },
            success: function(id, url, searchVal, result){
                console.log('id: example6_3, 成功返回数据!!!');
            }
        });

        //截止时间
        $('#date-end').datetimepicker({
            language: 'zh-CN',
            format: "yyyy-mm-dd hh:ii:ss",
            todayHighlight: true,
            autoclose: true,
            todayBtn: true
        });

        //提交数据
        form.on('submit(publish)',function (data) {
            console.log(data.field);
            $.post('', data.field, function(response) {
                if (response.code == 0) {
                    //重新加载页面
                    location.reload();
                    //跳转回首页
                } else {
                    layer.msg(response.msg,{icon: 2});
                }
            }, 'json');
        })
    })

});